/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogo;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;
import jogo.Entidade.*;

import java.util.ArrayList;
import jogo.Entidade.Botao;

import jogo.sprite.ImageStore;
import jogo.sprite.Sprite;
import jogo.sprite.SpriteStore;

/**
 *
 * @author IVAN
 */
public class FrmMenu extends javax.swing.JFrame
        implements Runnable , IVariaveisControle {

    private JogoStatusEnum statusJogo;
    private FrmJogo frmJogo;
    private FrmCreditos frmCreditos;
    private ArrayList<Botao> lstBotoes;
    private PlanoFundo bg;
    PlayIntro pIntro;

    /**
     * Creates new form FrmMenu
     */
    public FrmMenu() {
        statusJogo = statusJogo.Menu;
        initComponents();
        bg = new PlanoFundo("Back2.png");

//        pIntro = new PlayIntro();

        Botao btmTmp;
        createBufferStrategy(2);

        setup();

        lstBotoes = new ArrayList<>();
        //Iniciar
        btmTmp = new Botao("Iniciar", (250), 150, 300, 70);
        lstBotoes.add(btmTmp);
        //Creditos
        btmTmp = new Botao("Créditos", (250), 250, 300, 70);
        lstBotoes.add(btmTmp);
        //Ranking
        btmTmp = new Botao("Sair", (250), 350, 300, 70);
        lstBotoes.add(btmTmp);

        Thread t = new Thread(this);
        t.start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1366, 768));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        for (Botao b : lstBotoes) {
            if ((evt.getX() >= b.getRecButom().x) && (evt.getX() <= (b.getRecButom().width + b.getRecButom().x)) && (evt.getY() >= b.getRecButom().y) && (evt.getY() <= (b.getRecButom().height + b.getRecButom().y))) {
                switch (b.getStrTexto()) {
                    case "Iniciar":
                        statusJogo = statusJogo.Jogando;
                        this.setVisible(false);
                        pIntro.pauseIntroducao();
                        frmJogo = new FrmJogo(this);
                        break;
                    case "Créditos":                        
                        statusJogo = statusJogo.Creditos;
                        this.setVisible(false);
                        frmCreditos = new FrmCreditos(this);
                        break;
                    case "Sair":
                        System.exit(1);
                        break;
                    default:
                        break;
                }
            }
        }

    }//GEN-LAST:event_formMouseClicked

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmMenu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    //@Override
    public void run() {
        pIntro = new PlayIntro();

        pIntro.playIntroducao();

        while (statusJogo == JogoStatusEnum.Menu || statusJogo == JogoStatusEnum.Creditos) {
            Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics();

            g.setColor(Color.BLACK);
            g.fillRect(0, 0, getWidth(), getHeight());
            bg.desenhar(g);

            g.setColor(Color.white);
            for (Elemento e : lstBotoes) {
                e.desenhar(g);
            }

            //Desenha Plano de fundo do menu



            g.dispose();

            getBufferStrategy().show();

            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {
                Logger.getLogger(FrmJogo.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

    }

    void setup() {

        //Seta para fullScreen                                        
        //setUndecorated(true);

        this.setSize(800, 600);

        //setVisible(true);
    }

    public String ReturnMenuImagePath() {
        return "";
    }

    @Override
    public JogoStatusEnum getJogoStatusEnum() {
        return statusJogo;
    }

    @Override
    public void setJogoStatusEnum(JogoStatusEnum jogoStatusTmp) {
        statusJogo = jogoStatusTmp;
    }

    @Override
    public boolean getMenuVisible() {
        return (statusJogo == JogoStatusEnum.Menu);
    }

    @Override
    public void setMenuVisible(boolean visibilidade) {
        setVisible(visibilidade);                
    }
   
}
